import {
    validate
} from './validate';
import {
    submit
} from './submit';

import {
    createView
} from './views/create.view';
import {
    getSectionInfo,renderSectionView
} from './renderSectionView';
import{
    modal
}from '../common/layer';
const createBtnHandler = () => {


    modal('新增', createView());


    getSectionInfo(function (data) {
        renderSectionView(data,'#section');
    });

    $('#submitBtn').click(() => {
        let data = {};
        $.each($('#form').serializeArray(), (key, val) => {
            data[val.name] = $.trim(val.value);
        });
        if (!validate(data)) {
            return;
        }
        submit(GLOBAL_CreateUrl, data);
    });


};

export {
    createBtnHandler
}